function cloneDeep(obj: any): any {
  // console.log(Object.prototype.toString.call({ obj }));
  if (Object.prototype.toString.call(obj) === '[object Array]') {
    return obj.map((item: any) => cloneDeep(item));
  } else if (Object.prototype.toString.call(obj) === '[object Object]') {
    const res: any = {};
    for (const key in obj) {
      res[key] = cloneDeep(obj[key]);
    }
    return res;
  }
  return obj;
}

function localStorage(key: string, type: string, data?: any): any {
  let res: any;
  switch (type) {
    case 'setItem':
      {
        const JSONData = JSON.stringify(data);
        window.localStorage.setItem(key, JSONData);
      }
      break;
    case 'getItem':
      res = window.localStorage.getItem(key) ?? '';
      res = res ? JSON.parse(res) : null;
      break;
    case 'removeItem':
      window.localStorage.removeItem(key);
      break;
  }
  return res;
}

export { cloneDeep, localStorage };
